package com.myjob.handlerImpl;

import com.alibaba.dubbo.config.annotation.Service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.myjob.common.DubboConfig;
import com.myjob.config.MjServiceName;
import com.myjob.entity.Member;
import com.myjob.handler.MemberHandler;
import com.myjob.mapper.MemberMapper;
import com.myjob.utils.UtilValidate;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author Chen Yuan
 * @create 2021-01-28  15:53
 */
@Slf4j
@Component
@Service(group = MjServiceName.COMPANY,
		retries = DubboConfig.RETRIES,
		timeout = DubboConfig.TIME_OUT,
		version = DubboConfig.VERSION)
public class MemberHandlerImpl implements MemberHandler {
	@Autowired
	private MemberMapper memberMapper;
	/**
	 * 按照会员类型的名称查询会员信息
	 * @param typeName 会员类型名称
	 */
	@Override
	public Member selectOneMember(String typeName) {
		log.info("[Dubbo] - 被远程调用 -> MemberHandler -> selectOneMember("+typeName+")");
		if (UtilValidate.isEmpty(typeName)){
			return null;
		}
		QueryWrapper<Member> wrapper = new QueryWrapper<>();
		wrapper.eq("type_name", typeName);
		Member member = memberMapper.selectOne(wrapper);
		return member;
	}
}
